package com.clstu.Object_;

public class ToString_ {
    public static void main(String[] args) {
        Monster monster = new Monster("金角大王", "巡山", "200000");
        System.out.println(monster);//会默认调用toString()方法
        //输出对象就是相当于调用toString（） 方法，输出包名加类名再加上对象的hashCode() 十六进制表示

        //如果重写了ToString方法，就会默认调用重写的toString方法
    }
}

class Monster{
    private String name;
    private String job;
    private String sal;

    public Monster(String name, String job, String sal) {
        this.name = name;
        this.job = job;
        this.sal = sal;
    }

    @Override
    public String toString() {//重写toString方法
        return "Monster{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", sal='" + sal + '\'' +
                '}';
    }
}